package com.bsoft.client.config;

import com.bsoft.client.common.RequestMetadata;
import com.bsoft.client.processor.RpcClientProcessor;
import org.springframework.boot.context.properties.bind.Binder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.Environment;

@Configuration
public class BeanConfiguration {

    /**
     * 绑定环境变量到metadata上
     * @param environment
     * @return
     */
    @Bean
    public RequestMetadata requestMetadata(Environment environment){
        RequestMetadata requestMetadata = Binder.get(environment).bind("rpc.client", RequestMetadata.class).get();
        return requestMetadata;
    }

    /**
     * 后置处理类
     * @param metadata
     * @return
     */
    @Bean
    public RpcClientProcessor rpcClientProcessor(RequestMetadata metadata){
        return new RpcClientProcessor(metadata);
    }

}
